<?php

namespace app\http\middleware;

use app\helper\TokenHelper;

class AppTokenUnHard {

    /**
     * 通过token获取用户信息，这里并不是强制校验，有就校验，没有就不校验
     * @param \think\facade\Request $request
     * @param \Closure $next
     * @return mixed|\think\response\Json
     */
    public function handle($request, \Closure $next) {
//        $header = config('apiadmin.CROSS_DOMAIN');
        $ApiAuth = $request->header('apiAuth', '');
        if ($ApiAuth) {
            $userInfo = TokenHelper::getUserByToken($ApiAuth);
            if ($userInfo && isset($userInfo['uid'])) {
                $request->APP_USER_INFO = $userInfo;
            }
        }
        return $next($request);
    }
}
